﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CarRent.DAL;

namespace CarRent.BL.Models
{
    [Serializable]
    public class BookingInfo
    {
        const string Unknown = "Unknown";

        public string RequestBy { get; set; }
        public int? RequestFor { get; set; }
        public DateTime? CreatedDate { get; set; }
        public DateTime? FromDateTime { get; set; }
        public DateTime? ToDateTime { get; set; }
        public DateTime? DepartDateTime { get; set; }
        public DateTime? ArrivalDateTime { get; set; }
        public string Remark { get; set; }
        public string Remark2 { get; set; }
        public bool IsApproval { get; set; }
        public string Destination { get; set; }
        public string Purpose { get; set; }
        public decimal? StartKM { get; set; }
        public decimal? EndKM { get; set; }
        public int BookingID { get; set; }
        public int? CarID { get; set; }
        public string FullName { get; private set; }
        public string Department { get; private set; }
        public string FromTime { get; private set; }
        public string ToTime { get; private set; }
        public string FromDate { get; private set; }
        public string ToDate { get; private set; }
        public string RequestDate { get; private set; }

        public string DepartDate { get; private set; }
        public string DepartTime { get; private set; }
        public string ArrivalDate { get; private set; }
        public string ArrivalTime { get; private set; }
        public string Status { get; private set; }

        public string CarName { get; private set; }
        public string CarURL { get; private set; }

        public BookingInfo()
        {

        }

        public BookingInfo(Booking booking)
            : this()
        {
            if (booking.User != null)
            {
                FullName = booking.User.FullName ?? Unknown;
                if (booking.User.Dept != null)
                    Department = booking.User.Dept.DeptName ?? Unknown;
            }
            RequestBy = booking.RequestBy;
            RequestFor = booking.RequestFor;
            FromDateTime = booking.FromDate;
            ToDateTime = booking.ToDate;

            FromDate = FromDateTime.HasValue ? FromDateTime.Value.ToString("MM/dd/yyyy") : string.Empty;
            ToDate = ToDateTime.HasValue ? ToDateTime.Value.ToString("MM/dd/yyyy") : string.Empty;
            FromTime = FromDateTime.HasValue ? FromDateTime.Value.ToString("HH:mm") : string.Empty;
            ToTime = ToDateTime.HasValue ? ToDateTime.Value.ToString("HH:mm") : string.Empty;

            CreatedDate = booking.CreatedDate;
            RequestDate = CreatedDate.HasValue ? CreatedDate.Value.ToString("MM/dd/yyyy HH:mm") : string.Empty;

            IsApproval = booking.IsApproval;
            Remark = booking.Remark ?? string.Empty;
            Remark2 = booking.Remark2;
            Destination = booking.Destination;
            Purpose = booking.Purpose;
            DepartDateTime = booking.DepartTime;
            ArrivalDateTime = booking.ArrivalTime;

            DepartDate = DepartDateTime.HasValue ? DepartDateTime.Value.ToString("MM/dd/yyyy") : string.Empty;
            ArrivalDate = ArrivalDateTime.HasValue ? ArrivalDateTime.Value.ToString("MM/dd/yyyy") : string.Empty;
            DepartTime = DepartDateTime.HasValue ? DepartDateTime.Value.ToString("HH:mm") : string.Empty;
            ArrivalTime = ArrivalDateTime.HasValue ? ArrivalDateTime.Value.ToString("HH:mm") : string.Empty;

            StartKM = booking.StartKm;
            EndKM = booking.EndKm;
            BookingID = booking.BookingID;
            CarID = booking.CarID;

            if (CarID.HasValue)
            {
                CarName = booking.Car.CarName;
                CarURL = booking.Car.Picture;
            }

            Status = booking.IsDeleted ? "Deleted" : (IsApproval ? "Approved" : "Pending");
        }
    }
}
